# include "store.h"

void printar (Store *st) {
	int i,j,n;
	ArrayList *lst; Student *s;
	for (i=0;i<st->nUCEs;i++) {
		printf("UCE: %s\n",st->mapUCEs[i]);
		lst = st->uces[i];
		n = arrayGetLength(lst);
		for (j=0;j<n;j++) {
			s = arrayGet(lst,j);
			printf("  %s\n",s->name);
		}
	}
	for (i=0;i<st->nUCEs;i++) {
		for (j=0;j<i;j++) {
			printf("PESO ARESTA (%s,%s) = %d\n",st->mapUCEs[i],st->mapUCEs[j],getEdgeValue(st->allocationGraph,i,j));
		}
	}
	LinkedList *list = st->nonAllocatedStudents;
	printf("Não alocados!\n");
	while (list) {
		s = getData(list);
		printf(" %s\n",s->name);
		list = list->next;
	}
}
void printarGraph (Store *st, Graph *g) {
	int i;
	for (i=0;i<g->nodes;i++) {
		printf("UCE %s no horário %d\n",st->mapUCEs[i],g->color[i]);
	}
}
int main () {
	Store *calc = newStore();
	FILE *fp;
	fp = fopen("uces","r");
	ChainingHashMap *map = readUCEs(fp);
	fclose(fp);
	fp = fopen("students","r");
	ArrayList *sto = readStudents(fp);
	arraySort(sto,compareStudent,1);
	fclose(fp);
	fillInfo(calc,map,sto);
	initialDistribuition(calc,1,0,2);
	removeWorstEdge(calc);
	tryToAllocateNonAllocated(calc);
	tryToMakeSomeoneHappy(calc);
	Graph *g = getGraph(calc);
	g->maxColors = 10;
	int h = colorGraph(g);
	//printarGraph(calc,g);
	freeGraph(g);
	printar(calc);
	freeStore(calc);
	return 0;
}
